<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;

class Search extends Controller
{
    /**搜索
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index(Request $request)
    {
        $p = $request->post();
        $data = Db::name('article')->where('artname','like','%'.$p['artname'].'%')->find();

        $datas = Db::name('post')->where('postname',$p['artname'])->find();

        $column = Db::name('article')->where('column_id',3)->find();

        if((!empty($data) || !empty($datas)) && empty($column))
        {
           switch ($data['column_id'])
           {
               case 1:$this->redirect('index/Article/detail', ['id' => $data['art_id']]);break;
               case 2:$this->redirect('index/Recall/detail', ['id' => $data['art_id']]);break;
               case 4:$this->redirect('index/Share/detail', ['id' => $data['art_id']]);break;
               case 7:$this->redirect('index/Me/detail', ['id' => $data['art_id']]);break;
               default:$this->redirect('index/Post/detail', ['id' => $datas['post_id']]);
           }
        }else{
            echo "<script>alert('没有找到对应信息');window.history.back();</script>";
        }
    }
}
